package org.belkodevelop.controller;

import org.belkodevelop.course.domen.Course;
import org.belkodevelop.course.dto.CourseDto;
import org.belkodevelop.course.service.CourseService;
import org.dozer.DozerBeanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/api/currency/")
public class CurrencyController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private DozerBeanMapper mapper;

    @RequestMapping("/getCourse.json")
    @ResponseBody
    public CourseDto getCourse(@RequestParam String ccy, @RequestParam String baseCcy) {
        Course course = courseService.getCourse(ccy, baseCcy);
        CourseDto courseDto = mapper.map(course, CourseDto.class);
        return courseDto;
    }
}
